/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmRelatorio.java
 *
 * Created on 20/06/2011, 17:56:09
 */

package formularios;

import java.io.InputStream;
import java.util.HashMap;
import static dao.BancoDeDados.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Convidados1
 */
public class frmRelatorio extends javax.swing.JInternalFrame {

    /** Creates new form frmRelatorio */
    public frmRelatorio() {
        initComponents();
        try {
            conectarBancoDados();
        } catch (Exception ex) {
            Logger.getLogger(frmRelatorio.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bntRelClientes = new javax.swing.JButton();
        bntRelFornecedores = new javax.swing.JButton();
        bntRelMercadoria = new javax.swing.JButton();
        bntRelUsuarios = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createEtchedBorder());
        setClosable(true);

        bntRelClientes.setText("Relatório de Clientes");
        bntRelClientes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntRelClientesActionPerformed(evt);
            }
        });

        bntRelFornecedores.setText("Relatórios de Fornecedores");
        bntRelFornecedores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntRelFornecedoresActionPerformed(evt);
            }
        });

        bntRelMercadoria.setText("Relatório de Mercadorias");
        bntRelMercadoria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntRelMercadoriaActionPerformed(evt);
            }
        });

        bntRelUsuarios.setText("Relatório de Usuários");
        bntRelUsuarios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntRelUsuariosActionPerformed(evt);
            }
        });

        jLabel1.setText("Relatórios");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(bntRelUsuarios, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(bntRelFornecedores, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(bntRelMercadoria, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(bntRelClientes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addComponent(jLabel1)))
                .addContainerGap(39, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(32, 32, 32)
                .addComponent(bntRelClientes)
                .addGap(18, 18, 18)
                .addComponent(bntRelMercadoria)
                .addGap(18, 18, 18)
                .addComponent(bntRelFornecedores)
                .addGap(18, 18, 18)
                .addComponent(bntRelUsuarios)
                .addContainerGap(46, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bntRelClientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntRelClientesActionPerformed
        try {

            String reportName = "relatorios/cliente/relatorioCliente.jasper";
            InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);

            JasperPrint jasperPrint = JasperFillManager.fillReport(is, new HashMap(), cn);
            JasperViewer jv = new JasperViewer(jasperPrint, false);
            jv.setVisible(true);

        } catch (JRException ex) {
            Logger.getLogger(frmRelatorio.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_bntRelClientesActionPerformed

private void bntRelFornecedoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntRelFornecedoresActionPerformed
    try {

            String reportName = "relatorios/fornecedor/relatorioFornecedor.jasper";
            InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);

            JasperPrint jasperPrint = JasperFillManager.fillReport(is, new HashMap(), cn);
            JasperViewer jv = new JasperViewer(jasperPrint, false);
            jv.setVisible(true);

        } catch (JRException ex) {
            Logger.getLogger(frmRelatorio.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_bntRelFornecedoresActionPerformed

private void bntRelMercadoriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntRelMercadoriaActionPerformed
    try {

            String reportName = "relatorios/mercadoria/relatorioMercadoria.jasper";
            InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);

            JasperPrint jasperPrint = JasperFillManager.fillReport(is, new HashMap(), cn);
            JasperViewer jv = new JasperViewer(jasperPrint, false);
            jv.setVisible(true);

        } catch (JRException ex) {
            Logger.getLogger(frmRelatorio.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_bntRelMercadoriaActionPerformed

private void bntRelUsuariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntRelUsuariosActionPerformed
    try {

            String reportName = "relatorios/usuario/relatorioUsuario.jasper";
            InputStream is = this.getClass().getClassLoader().getResourceAsStream(reportName);

            JasperPrint jasperPrint = JasperFillManager.fillReport(is, new HashMap(), cn);
            JasperViewer jv = new JasperViewer(jasperPrint, false);
            jv.setVisible(true);

        } catch (JRException ex) {
            Logger.getLogger(frmRelatorio.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_bntRelUsuariosActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bntRelClientes;
    private javax.swing.JButton bntRelFornecedores;
    private javax.swing.JButton bntRelMercadoria;
    private javax.swing.JButton bntRelUsuarios;
    private javax.swing.JLabel jLabel1;
    // End of variables declaration//GEN-END:variables

}
